//
//  TMGNewMineViewController.m
//  TMGold
//
//  Created by Mac on 2017/12/8.
//  Copyright © 2017年 tangmu. All rights reserved.
//

#import "TMGNewMineViewController.h"
#import "TMGMineHeaderView.h"
#import "TMGMineFooterView.h"
#import "TMGSettingViewController.h"
#import "TMGPersonalCenterController.h"
#import "TMGMineOrderViewController.h"
#import "TMGHelpCenterViewController.h"
#import "STDiscountsViewController.h"
#import "TMGFetchGoldViewController.h"
#import "TMGGoldAssetViewController.h"
#import "TMGPlanViewController.h"
#import "TMGMineHomeModel.h"
#import "TMGAccountViewController.h"
#import "TMGEarningsDetailViewController.h"
#import "TMGMessageListViewController.h"
#import "TMGInviteFriendViewController.h"
#import "TMGMessageViewController.h"
@interface TMGNewMineViewController ()<TMGMineHeaderViewDelegate,TMGMineFooterViewDelegate>
@property(nonatomic, strong) TMGMineHeaderView                     *header;
@property(nonatomic, strong) TMGMineFooterView                     *footer;
@property(nonatomic, strong) TMGMineHomeModel                     *model;
@end

@implementation TMGNewMineViewController

#pragma mark --vc 生命周期
- (void)viewDidLoad{
    [super viewDidLoad];
    self.tableView.height = self.tableView.height - 44;
    [self configSubView];
    [self st_setLeftItemWithImage:[UIImage imageNamed:@"个人资料"]];
    [self st_setRightItemWithImage:[UIImage imageNamed:@"icon设置"]];

}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self sendMoneyRequest];
    [TMUtils fetchPersonnalInfo:^(TMGUserModel *user) {
        [[STUserManger defult] updateUserModel:user];
        self.header.model = self.header.model;
    }];
}
- (void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
}
- (void)viewDidDisappear:(BOOL)animated{
    [super viewDidDisappear:animated];
}
#pragma mark --subView
- (void)configSubView{
    self.header = [[TMGMineHeaderView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 100)];
    self.header.delegate = self;
    self.tableView.tableHeaderView = self.header;
    
    self.footer = [[TMGMineFooterView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 100)];
    self.footer.backgroundColor = UIColorFromRGBA(0xf1f2f7);
    self.footer.delegate = self;
    self.tableView.tableFooterView = self.footer;
    

}
- (void)st_leftBarAction:(id)sender{
    [self.navigationController pushViewController:[TMGPersonalCenterController new] animated:YES];
}
- (void)st_rightBarAction:(id)sender{
    [self.navigationController pushViewController:[TMGSettingViewController new] animated:YES];
}
#pragma mark --TMGMineFooterViewDelegate
- (void)onSlectedMenuButton:(NSString *)title{
    if ([title isEqualToString:@"我的订单"]) {
        [self.navigationController pushViewController:[TMGMineOrderViewController new] animated:YES];
    }
    if ([title isEqualToString:@"帮助中心"]) {
        [self.navigationController pushViewController:[TMGHelpCenterViewController new] animated:YES];
    }
    if ([title isEqualToString:@"优惠券"]) {
        [self.navigationController pushViewController:[[STDiscountsViewController alloc] initWithType:TMGDiscountTypeDeflut] animated:YES];
    }
    if ([title isEqualToString:@"我的红包"]) {
        [self.navigationController pushViewController:[[STDiscountsViewController alloc] initWithType:TMGDiscountTypeHongbao] animated:YES];
    }
    if ([title isEqualToString:@"提金"]) {
        [self.navigationController pushViewController:[TMGFetchGoldViewController new] animated:YES];
    }
    if ([title isEqualToString:@"消息"]) {
        [self.navigationController pushViewController:[TMGMessageViewController new] animated:YES];
        
    }
    if ([title isEqualToString:@"图片"]) {
        NSString * url = [NSString stringWithFormat:@"http://jshjkd.com/gold/public/home/web/friend?uid=%@",[STUserManger defult].userID];
        TMGInviteFriendViewController * webvc = [[TMGInviteFriendViewController alloc] initWithUrl:url];
        webvc.progressBackgroundColor = [UIColor whiteColor];
        webvc.progressTintColor = TM_orangeColor;
        webvc.forceTitle = @"邀请好友";
        [self.navigationController pushViewController:webvc animated:YES];
    }

}
#pragma mark --TMGMineHeaderViewDelegate
- (void)headerViewOnSlectedMenuButton:(NSString *)title{
    if ([title isEqualToString:@"黄金资产"]) {
        [self.navigationController pushViewController:[TMGGoldAssetViewController new] animated:YES];
    }
    if ([title isEqualToString:@"投资计划"]) {
        
        [self.navigationController pushViewController:[TMGPlanViewController new] animated:YES];
    }
    if ([title isEqualToString:@"账户余额"]) {
        TMGAccountViewController * vc = [TMGAccountViewController new];
        vc.money = self.model.money.description;
        [self.navigationController pushViewController:vc animated:YES];
    }
    if ([title isEqualToString:@"查看收益明细"]) {
        [self.navigationController pushViewController:[TMGEarningsDetailViewController new] animated:YES];
    }
    
}
#pragma mark --NetWork Method
- (void)sendMoneyRequest{
    NSMutableDictionary * dic = [NSMutableDictionary new];
    if ([STUserManger defult].userID.length) {
        [dic setObject:[STUserManger defult].userID forKey:@"uid"];
    }
    if ([STUserManger defult].token.length) {
        [dic setObject:[STUserManger defult].token forKey:@"token"];
    }
    NSString * url = [NSString stringWithFormat:@"%@%@",service_header,@"/gold/public/api/personal/personalCenter"];
    [[STNetWrokManger defaultClient] requestWithPath:url
                                              method:STHttpRequestTypePost
                                          parameters:dic
                                             success:^(NSURLSessionDataTask *operation, id responseObject) {
                                                 
                                                 self.model = [TMGMineHomeModel mj_objectWithKeyValues:responseObject[@"data"]];
                                                 self.header.model = self.model;
                                                
                                                 [SVProgressHUD dismiss];
                                                 
                                             } failure:^(NSString *stateCode, STError *error) {
                                                 [SVProgressHUD dismiss];
                                                 [SVProgressHUD showErrorWithStatus:error.desc];
                                             }];
}
@end

